package com.sky.result;

import java.io.Serializable;
import java.util.HashMap;

public class Result extends HashMap<String, Object> implements Serializable {
    private static final String CODE_TAG = "code";

    private static final String MSG_TAG = "msg";

    private static final String DATA_TAG = "data";

    public Result() {
    }

    public Result(Integer code, String msg) {
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
    }

    public Result(Integer code, String msg, Object data) {
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
        super.put(DATA_TAG, data);
    }

    public static Result success(String msg, Object data) {
        return new Result(200, msg, data);
    }

    public static Result success(String msg) {
        return new Result(200, msg);
    }

    public static Result success(Object data) {
        return Result.success("操作成功", data);
    }

    public static Result success() {
        return Result.success("操作成功");
    }

    public static Result error(String msg, Object data) {
        return new Result(500, msg, data);
    }

    public static Result error(String msg) {
        return new Result(500, msg);
    }

    public static Result error(Object data) {
        return Result.error("操作失败", data);
    }

    public static Result error() {
        return Result.error("操作失败");
    }

    public static Result error(Integer code, String msg) {
        return new Result(code, msg);
    }
}
